home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / timeline / blanktim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  11.0 KB  |  260 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/TimeLine/RCS/blankTime.c,v 1.0 91/09/30 16:49:23 chua Exp Locker: drapeau $ */
  25. /* $Log:    blankTime.c,v $
  26.  * Revision 1.0  91/09/30  16:49:23  chua
  27.  * Update to version 1.0
  28.  * 
  29.  * Revision 0.67  91/09/23  17:06:30  chua
  30.  * Insert Blank Time has been moved from the Edit menu button to the Options
  31.  * menu button
  32.  * 
  33.  * Revision 0.66  91/09/19  17:28:38  chua
  34.  * Make sure that variables are initialized properly.  Change formatting slightly,
  35.  * so that (if, for, while) statements with only one statement in them will not have
  36.  * braces.
  37.  * 
  38.  * Revision 0.65  91/09/04  15:05:02  chua
  39.  * Replaced the notice_prompt call by a call to AlertMessage.
  40.  * 
  41.  * Revision 0.64  91/07/30  17:32:20  chua
  42.  * When blank time is inserted, set the change flag to 1.
  43.  * 
  44.  * Revision 0.63  91/07/24  17:45:54  chua
  45.  * In the InsertBlankTime procedure, add a check to see if a note or area has been selected.
  46.  * If so, replace this selected area by the amount of blank time specified.
  47.  * 
  48.  * Revision 0.62  91/07/22  15:15:02  chua
  49.  * Changed the name of the pointer to the blank time popup window to InsertBlankTimePopup,
  50.  * instead of a longer name previously.
  51.  * 
  52.  * Revision 0.61  91/07/17  16:30:13  chua
  53.  * In the CancelBlankTime routine, just use the ip pointer to find the pointer to the
  54.  * popup window, instead of using tlFrame etc.
  55.  * 
  56.  * Revision 0.60  91/07/17  10:14:03  chua
  57.  * In line 169, there is a slight change, as the lastX variable now represents time
  58.  * stored in the lowest zoom level (same as start), so there is no need to multiply
  59.  * by the zoom level.
  60.  * 
  61.  * Revision 0.59  91/07/09  18:23:37  chua
  62.  * Made changes to the startX, endX variables so that they now store the position at the
  63.  * largest zoom level (zoom level = 1).   Thus, the appropriate multiplication or
  64.  * division by the zoom level has to be made when these variables are used.  This will
  65.  * include lastX (position of the playback head) as well.
  66.  * 
  67.  * Revision 0.58  91/07/09  16:52:46  chua
  68.  * In the InsertBlankTime routine, check if the playback head has been positioned on the
  69.  * canvas.  If not, print a message and exit the procedure.
  70.  * 
  71.  * Revision 0.57  91/06/24  16:52:43  chua
  72.  * In the InsertBlankTime procedure (line 136), as the constant HalfSecondScale is no longer
  73.  * used, it is replaced by its value, 5.
  74.  * 
  75.  * Revision 0.56  91/06/04  17:37:07  chua
  76.  * Added the copyright comments in the beginning of the file.
  77.  * 
  78.  * Revision 0.55  91/06/04  10:41:25  chua
  79.  * Added a call to UpdateHeader whenever there is a change in the status of
  80.  * the current document (the change flag set to 1).
  81.  * 
  82.  * Revision 0.54  91/06/03  11:09:42  chua
  83.  * Make changes to accomodate multiple documents.  This involves identifying
  84.  * which window the blank time popup window belongs to.
  85.  * 
  86.  * Revision 0.53  91/05/30  12:07:07  chua
  87.  * Added an extra parameter in the call to InitNotesInfo.  The second parameter,
  88.  * deselect, indicates if the currently selected note is to be deselected.
  89.  * 
  90.  * Revision 0.52  91/05/29  14:28:37  chua
  91.  * Delete the ClearNoteInfoList function call in line 129, since the InitNotesInfo has been 
  92.  * rewritten such that the ClearNoteInfoList call is not necessary.
  93.  * 
  94.  * Revision 0.51  91/05/28  12:09:27  chua
  95.  * *** empty log message ***
  96.  * 
  97.  * Revision 0.50  91/05/24  16:35:42  chua
  98.  * *** empty log message ***
  99.  * 
  100.  * Revision 0.49  91/05/23  17:33:18  chua
  101.  * This file contains the functions to deal with inserting blank time onto either a selected track or
  102.  * all tracks.  The functions are:
  103.  * 
  104.  * InsertBlankTimeHandler - displays the Insert Blank Time popup window.
  105.  * InsertBlankTime - Button notify procedure which performs the insertion of blank time onto either
  106.  *              a selected track or all tracks, depending on what the user has chosen.
  107.  * CancelBlankTime - Button notify procedure/Done procedure for the Insert Blank Time popup window.
  108.  *              Closes the popup window when the user no longer requires it.  Called by eitther
  109.  *              pressing the Cancel button or releasing the pushpin.
  110.  *  */
  111.  
  112. static char blankTimercsid[] = "$Header: /Source/Media/collab/TimeLine/RCS/blankTime.c,v 1.0 91/09/30 16:49:23 chua Exp Locker: drapeau $";
  113.  
  114. #include "main.h"
  115.  
  116. /*
  117.  * Menu handler for `OptionsMenu (Insert Blank Time ...)'.
  118.  * This function will pop up the Insert Blank Time pop-up window, so that the user can choose how much blank time and where to insert the
  119.  * blank time.
  120.  */
  121. Menu_item InsertBlankTimeHandler(item, op)
  122.      Menu_item    item;
  123.      Menu_generate    op;
  124. {
  125.   TimeLineFramePtr tlFrame;
  126.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  127.  
  128.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  129.   switch (op) 
  130.   {
  131.    case MENU_DISPLAY:
  132.     break;
  133.    case MENU_DISPLAY_DONE:
  134.     break;
  135.    case MENU_NOTIFY:
  136.     xv_set(tlFrame->InsertBlankTimePopup->InsertBlankTimePopup,
  137.        FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  138.     xv_set(tlFrame->InsertBlankTimePopup->InsertBlankTimePopup,
  139.        XV_SHOW, TRUE, NULL);
  140.     break;
  141.    case MENU_NOTIFY_DONE:
  142.     break;
  143.   }
  144.   return item;
  145. }
  146.  
  147. /*
  148.  * Notify callback function for `InsertBlankTimeButton'.
  149.  * This function will insert blank time onto either a selected track or all tracks, depending on what the user chose.
  150.  * First, it will check if an area or note has been selected. If so, it will delete the selected area/note and move the playback head to the start of
  151.  * the deleted area.
  152.  * It will then determine whether it is a single track or all track insert.  It then checks to see that the playback head has been positioned
  153.  * at some place and that if a single track is chosen, make sure an application has been selected.
  154.  * Next, the blank time to be inserted is calculated from the text fields in the pop-up window.
  155.  * The function then loops through all the instruments where the blank time is to be inserted to find out at which spot in the note list the blank time
  156.  * is to be inserted.
  157.  * Insertion is then performed.  This is done basically by updating the times of all notes following the insertion point.  If the insertion point falls in
  158.  * the middle of a note, the blank space is inserted after the note.
  159.  */
  160. void InsertBlankTime(item, event)
  161.      Panel_item    item;
  162.      Event        *event;
  163. {
  164.   int         found, choice, i;
  165.   int         startApp, endApp;
  166.   Instrument     *instrument;
  167.   long         blankTime;
  168.   int         inserted;
  169.   Note         *prevNote, *currentNote, *nextNote;
  170.   TimeLineFramePtr tlFrame;
  171.   BlankTime_InsertBlankTimePopup_objects    *ip = (BlankTime_InsertBlankTimePopup_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  172.   Window    owner = xv_get(ip->InsertBlankTimePopup, XV_OWNER);
  173.   TimeLine_window_objects * tlip = (TimeLine_window_objects *) xv_get(owner, XV_KEY_DATA, INSTANCE);
  174.  
  175.   tlFrame = TimeLineWindow[xv_get(tlip->controls, PANEL_CLIENT_DATA)];
  176.   if (tlFrame->areaSelected || tlFrame->noteSelected)            /* Check if either a note or an area is selected */
  177.   {
  178.     DeleteNotesFromList(0, tlFrame);
  179.     DrawPlaybackHead(tlFrame->startX, tlFrame);
  180.   }
  181.   if (tlFrame->lastX < 0)                        /* Check if the playback head is on the canvas */
  182.   {
  183.     AlertMessage(tlFrame, "You must position the insertion point (playback head)",
  184.          "on the canvas first.", NULL);
  185.     return;
  186.   }
  187.   startApp = tlFrame->chosenApp;
  188.   endApp = tlFrame->chosenApp + 1;
  189.   choice = xv_get(tlFrame->InsertBlankTimePopup->InsertBlankTimeChoice, PANEL_VALUE);
  190.   if (choice == 1)                            /* Insert for all tracks */
  191.   {
  192.     startApp = 0;
  193.     endApp = tlFrame->numberOfApps;
  194.   }
  195.   inserted = 0;
  196.   if (tlFrame->lastX >= 0 && startApp >= 0)                /* Check that the playback head is positioned someplace */
  197.   {
  198.     blankTime = xv_get(tlFrame->InsertBlankTimePopup->MinTimeText, PANEL_VALUE) * 60 + /* Calculate the blank time in seconds */
  199.       xv_get(tlFrame->InsertBlankTimePopup->SecTimeText, PANEL_VALUE);
  200.     blankTime = blankTime * PixelsPerSecond;                /* Set the blank time to 1/10 second scale (the scale for zoomLevel = 1) */
  201.     instrument = (Instrument *) FindInstrument(startApp, tlFrame);
  202.     if (instrument == NULL) 
  203.       return;
  204.     for (i=startApp; i < endApp; i++) 
  205.     {
  206.       if (instrument->firstNote != NULL)                /* Check that there are notes in this instrument.  Else no point adding blank time */
  207.       {
  208.     currentNote = instrument->firstNote;                /* Go through the instrument note list to determine at which point in the */
  209.     prevNote = currentNote;                        /* note list should the insertion of blank time should occur */
  210.     found = 0;
  211.     while (currentNote != NULL && !found) 
  212.     {
  213.       if (currentNote->start >= tlFrame->lastX)
  214.         found = 1;
  215.       else 
  216.       {
  217.         prevNote = currentNote;
  218.         currentNote = currentNote->next;
  219.       }
  220.     }
  221.     if (currentNote == instrument->firstNote)            /* Paste before all the notes in the current note list */
  222.       nextNote = instrument->firstNote;
  223.     else 
  224.       nextNote = prevNote->next;                    /* duplicated clipboard note list */
  225.     while (nextNote != NULL)                    /* Update the start and end positions of the notes following the selected region */
  226.     {
  227.       inserted = 1;
  228.       nextNote->start += blankTime;
  229.       nextNote->end += blankTime;
  230.       CalculateNoteTime(nextNote);
  231.       nextNote = nextNote->next;
  232.     }
  233.       }
  234.       InitNotesInfo(instrument, 1, tlFrame);                /* Update the info pop-up window */
  235.       instrument = instrument->next;
  236.     }
  237.     if (inserted == 1)                            /* Set change flag on only if the document is affected by the inserted blank time */
  238.     {
  239.       tlFrame->change = 1;                        /* Set the change flag on */
  240.       UpdateHeader(tlFrame, 1);
  241.     }
  242.     DrawCanvasRepaintHandler(tlFrame->TimeLine_window->DrawCanvas, tlFrame->paintWinDraw, 
  243.                  tlFrame->dpyDraw, tlFrame->xidDraw, NULL);
  244.   }
  245. }
  246.  
  247. /*
  248.  * Notify callback function for `CancelBlankTimeButton'.
  249.  * This function hides the insert blank time popup window.
  250.  */
  251. void CancelBlankTime(item, event)
  252.      Panel_item    item;
  253.      Event        *event;
  254. {
  255.   BlankTime_InsertBlankTimePopup_objects    *ip = (BlankTime_InsertBlankTimePopup_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  256.  
  257.   xv_set(ip->InsertBlankTimePopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  258.   xv_set(ip->InsertBlankTimePopup, XV_SHOW, FALSE, NULL);
  259. }
  260.